import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Switch, Tag } from 'ant-design-vue';
import { getLevelSelectsApi, getCategorySelectsApi } from '@/api/sys/common';

import { useMessage } from '@/hooks/web/useMessage';
import Ainput from '@/views/bookManage/components/account/Ainput.vue';
import { rewardsSelectListApi } from '@/api/sys/rewards';

type CheckedType = boolean | string | number;
export const columns: BasicColumn[] = [
  {
    title: '姓名',
    dataIndex: 'userName',
  },
  {
    title: '积分',
    dataIndex: 'integral',
    width: 180,
  },
  {
    title: '获得/扣除',
    dataIndex: 'type',
    width: 100,
    customRender: ({ record }) => {
      const type = record.type;
      let text = '';
      if (type == 1) {
        text = '获得';
      }
      if (type == 2) {
        text = '扣除';
      }

      return text;
    },
  },
  {
    title: '获得积分的类型',
    dataIndex: 'readType',
    width: 120,
    customRender: ({ record }) => {
      const readType = record.readType;
      let text = '';

      if (readType == 1) {
        text = '满勤或全勤';
      }
      if (readType == 2) {
        text = '读书累计时长';
      }
      if (readType == 3) {
        text = '连续打卡天数';
      }
      return text;
    },
  },
  {
    title: '打卡类型',
    dataIndex: 'sysNote',
    width: 180,
  },
  {
    title: '打卡日期',
    dataIndex: 'day',
    width: 120,
  },
  {
    title: '系统信息',
    dataIndex: 'note',
    width: 180,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '姓名',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'type',
    label: '获得/扣除',
    component: 'Select',
    componentProps: {
      options: [
        { label: '获得', value: 1 },
        { label: '扣除', value: 2 },
      ],
    },
    colProps: { span: 6 },
  },
  {
    field: 'readType',
    label: '积分类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '其他', value: 0 },
        { label: '满勤或全勤', value: 1 },
        { label: '读书累计时长', value: 2 },
        { label: '连续打卡天数', value: 3 },
      ],
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'userId',
    component: 'Input',
    // rules: [{ required: true }],
    required: true,
    render: ({ model, field }) => {
      return h(Ainput, {
        placeholder: '请选择人员',
        //value: model[field],
        value: model.userName,
        mode: 'single', // multiple 多选 single 单选
        onChange: (e: ChangeEvent) => {
          model[field] = e.ids;
          model.userName = e.names;
        },
      });
    },
  },
  {
    field: 'userName',
    label: 'userName',
  },
  {
    field: 'integral',
    label: '积分',
    required: true,
    component: 'InputNumber',
  },
  {
    field: 'note',
    label: '缘由',
    component: 'Input',
    required: true,
  },
];

export const addIntegralformSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'userName',
    component: 'Ainput',
    required: true,
  },
  {
    field: 'integral',
    label: '积分',
    required: true,
    component: 'InputNumber',
  },
  {
    field: 'note',
    label: '缘由',
    component: 'Input',
    required: true,
  },
  {
    field: 'day',
    label: '所属日期',
    placeholder: '不填默认当天',
    component: 'DatePicker',
    required: false,
  },
];
